<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Vue 动态组件与on-once</title>
    <script charset="UTF-8" src="js/vue.js"></script>
</head>
<body>
<div id="app">
    <!--可行方法一-->
    <child-one v-if="type==='child-one'"></child-one>
    <child-two v-if="type==='child-two'"></child-two>
    <!--可行方法二：动态组件-->
    <!--<component :is="type"></component>-->
    <button @click="handleClick">change</button>
</div>
<script>
    //v-once  可有效提高内容的展示效率，一次展示后存入内存。不会重复销毁重建
    Vue.component('child-one',{
        template:"<div v-once>child-one</div>"
    });
    Vue.component('child-two',{
        template:"<div v-once>child-two</div>"
    });
    let vm = new Vue({
        el: '#app',
        data:{
            type:"child-one"
        },
        methods:{
            handleClick:function () {
                this.type=this.type==="child-one"? "child-two":"child-one";
            }
        }
    });
</script>
</body>
</html>